package com.highper.common.configuration;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.id.SaIdUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author ZhangGJ
 * @Date 2022/02/07 10:29
 */
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

    @Bean
    public SaServletFilter getSaServletFilter() {
        return new SaServletFilter().addInclude("/**").addExclude("/favicon.ico").setAuth(obj -> {
            String token = SaHolder.getRequest().getHeader(SaIdUtil.ID_TOKEN);
            SaIdUtil.checkToken(token);
        });
    }
}
